package reflect;

import reflect.annotations.AutoRunClass;

import java.io.File;
import java.lang.reflect.Method;

/**
 * 输出当前Test4在同一个包下所有的类是否被@AutoRunClass标注
 */
public class Test4 {
    public static void main(String[] args) throws Exception {
        File dir = new File(Test3.class.getResource(".").toURI());
        String packName = Test3.class.getPackage().getName();
        File[] subs = dir.listFiles(f -> f.getName().endsWith(".class"));
        for (File sub : subs) {
            String fileName = sub.getName();
            String className = fileName.substring(0, fileName.indexOf("."));// substring(beginIndex,endIndex);;;indexOf(".")返回"."的数组下标
            Class cls = Class.forName(packName + "." + className);

            boolean tf = cls.isAnnotationPresent(AutoRunClass.class);
            System.out.println(className+"类:"+(tf?"被标注了":"没有被标注"));
        }
    }
}
